home *** CD-ROM | disk | FTP | other *** search
- { Fixes to Custom Clipboard Formats article from Issue 3 }
- { See Xavier Pacheco's note on page 51 of this issue }
-
- { PasteFromClipboard OLD version }
- procedure TBirthday.PasteFromClipBoard;
- var
- Data: THandle;
- DataPtr: Pointer;
- C: Char;
- Size: Integer;
- begin
- Data := ClipBoard.GetAsHandle(CF_BIRTHDAY); { Get the data on the clipboard }
- try
- if Data = 0 then Exit; { Exit is unsuccessful }
- DataPtr := GlobalLock(Data); { Lock the Global memory object }
- try
- if SizeOf(FPersonRec) > GlobalSize(Data) then Size := GlobalSize(Data);
- { Copy contents of DataPtr to Buffer }
- Move(DataPtr^, FPersonRec, SizeOf(FPersonRec));
- finally
- GlobalUnlock(Data); { Unlock the global memory object }
- end;
- except
- GlobalFree(Data); { Free the memory allocated, only if }
- raise; { an exception occurs as this memory is }
- end; { managed by the Windows }
- end;
-
- { NEW fixed version (Listing 1 in Xavier's note on the fix) }
- procedure TBirthday.PasteFromClipBoard;
- var
- Data: THandle;
- DataPtr: Pointer;
- Size: Integer;
- begin
- Data := ClipBoard.GetAsHandle(CF_BIRTHDAY); { Get the data on the clipboard }
- if Data = 0 then Exit; { Exit is unsuccessful }
- DataPtr := GlobalLock(Data); { Lock the Global memory object }
- try
- if SizeOf(FPersonRec) > GlobalSize(Data) then
- Size := GlobalSize(Data)
- else
- Size := SizeOf(FPersonRec);
- { Copy contents of DataPtr to Buffer }
- Move(DataPtr^, FPersonRec, Size);
- finally
- GlobalUnlock(Data); { Unlock the global memory object }
- end;
- end;